parse abbreviated, sloppy, and informal timezone names
npm install timezone-soft
by
Spencer Kelly
(formerly called 'spacetime-informal')
import soft from 'timezone-soft'
let timezones = soft('milwaukee')[0]
IANA timezone codes are the official reference for timezone information, and is what you should use, whenever possible.
Humans though, are goofballs, and use a whole different informal scheme:
- In (North) America: PST, MST, EST...
- in Europe (lately): WEST, CEST, EEST...
- in Africa: EAT, CAT, WAST...
- in Australia: AWST, AEDT, ACST...
these line-up with the IANA codes sometimes.
...other times they don't.
These names also collide -
'IST' is used to mean:
- 'Indian Stardard Time'
- 'Irish Stardard Time'
- 'Israeli Stardard Time'
These names also produce all-sorts of ambiguities, regarding DST-changes-
Both Winnipeg and Mexico City are CST, but have a much different DST schedule:
![image](https://user-images.githubusercontent.com/399657/52489224-b34d0e00-2b8f-11e9-9de8-0688bec52464.png)
(thanks timeanddate.com!)
-of course, there's a bunch of political/historical/disputed stuff going on, too. Apologies if this library steps into that unknowingly.
...so that's what we're trying to fix - to 'soften' this exchange, between human and IANA timezone nomenclature, using some opinionated-but-common-sense rules and decision-making.
It was originally built for use in the spacetime timezone library.
Usage
const soft = require('timezone-soft')
soft('EST')
soft('central')
soft('venezuela')
soft('south east asia')
Typescript/Deno/Webpack:
import soft from 'timezone-soft'
it was built to be as forgiving as possible, and return the most common-sense IANA timezone id from user-input.
DST
Often, the proper timezone name will depend on which date you are referencing.
You can reckon this pretty-easily with spacetime, like this:
const spacetime = require('spacetime')
const soft = require('timezone-soft')
let display = soft('montreal')[0]
let show = display.standard.abbrev
let s = spacetime.now(display.iana)
if (display.daylight && s.isDST()) {
show = display.daylight.abbrev
}
console.log(s.time() + ' ' + show)
work-in-progress!
See also
MIT